//品牌管理
$(function(){
	//构建列表
	getList();

	//批量删除
	$("#batchDelBtn").click(function(){
		var c = "";
		$("input[name=datachk]:checked").each(function(){
			c += $(this).val()+',';
		});
		if(c!= null && c!=''){
			deleteBrand(c);
		}else{
			sy.toast("请选择删除项");
		}
	});

	// 起止日期选择
	laydate.render({
		elem: '#startEndDate',
		theme: 'molv',
		range: '~',
		max: 0,
		done: function(value, date, endDate){
			if (value != '') {
				var startTime = value.split(" ~ ")[0];
				var endTime = value.split(" ~ ")[1];
				$("#startTime").val(startTime);
				$("#endTime").val(endTime);
			}
		}
	});

	// 点击清空按钮
	$("#reset").on("click", function() {
		$("#startTime").val("");
		$("#endTime").val("");
	});

	/*$("#eventType").getSelect({
		type:"screen",
		label:"事件类型：",
		asName:"eventType",
		code:"eventType"
	});*/

	$("#eventProgress").getSelect({
		type:"screen",
		label:"上报事件进度：",
		asName:"eventProgress",
		code:"eventProgress"
	});
});


/**
 * 数据列表
 */
function getList(){
	console.log("事件管理");
	//构建列表
	$('#eventList').getList({
		"initData":{
			"size":10,
			"num":1
		},
		"url":site.apiUrl+"/moble/userEvent/selectEventList",// 数据请求url
		"type":"get",
		"checkname":"datachk", //选择器名称，为空不显示选择器
		"ajaxform":true,
		"col":[  //数据列
			{"field":"userNikeName","display":"姓名","width":"2"},
			{"field":"envetContext","display":"事件内容","width":"2"},
			{"field":"eventLog","display":"经度","width":"2"},
			{"field":"eventLat","display":"纬度","width":"2"},
			{"field":"eventProgressDisplay","display":"事件状态","width":"2"},
			{"field":"eventTypeDisplay","display":"事件类型","width":"2"},
		],
		"option":[ //操作按钮配置
			/*{"icon":"view","tip":"查看","fun":"brandView('{{id}}')"},  //icon: view,edit,add,del*/
			{"icon":"edit","tip":"编辑","fun":"brandEdit('{{id}}')"}, // 花括号内可以对应相关字段
			// {"icon":"del","tip":"删除","fun":"deleteBrand('{{id}}')"}
		]
	});
}



//编辑
function brandEdit(id){
	 ly.goto("EventList-creat.html?id="+id+"&dictBasicType=2")
}

//删除
function deleteBrand(id){
	var url = site.interUrl+"/banner/deleteBannerByIds";
	 request({
		url:url,
		data:{"ids":id},
		type:"get",
		callback:function(f) {
			console.log(f);
			if(f.code=="rest.success"){
				sy.toast("删除成功");
				$("#brandList").getList.refresh();//刷新当前分页
			}
		}
	});	
}

//查看
function commodityView(id){
	
	
}

function changePic(v, o, d) {
	if(d.picDisplay!=null && d.picDisplay!= ''){
		$(o).html("<img src="+d.picDisplay+" width='30' height='30'>");
	}else{
		$(o).html("<img src='"+site.interUrl+"images/default_head.jpg' width='30' height='30'>");
	}
}